<?php
	$hide = $_GET["hide"];
	$conn = mysqli_connect("127.0.0.1","root","","jyMovie");
	mysqli_query($conn,"SET NAMES utf8");
	if($hide == 1){
		$username = $_GET["username"];
		$psw = $_GET["psw"];
		$email = $_GET["email"];
		$SQL = "INSERT INTO user VALUES(0,'$username','$psw','$email','0')";
		$rs = mysqli_query($conn,$SQL);
		if($rs){
			echo ("<script>open('html/login.html','_self')</script>");
		}else{
			echo ("<script>open('html/register.html','_self')</script>");
		}
	}else if($hide == 2){
		$SQL = "SELECT username FROM user";
		$rs = mysqli_query($conn,$SQL);
		$arr = [];
		while(($row=mysqli_fetch_row($rs))!=null){
			array_push($arr,$row);
		}
		echo JSON_encode($arr);
	}else if($hide == 3){
		$username = $_GET["username"];
		$psw = $_GET["psw"];
		$SQL = "SELECT username,psw,id FROM user";
		$rs = mysqli_query($conn,$SQL);
		while(($row = mysqli_fetch_assoc($rs))!=null){
			echo($row["username"]);
			if($row["username"] == $username && $row["psw"] == $psw){
				$id = $row["id"];
				$name = $row["username"];
				echo("<script>sessionStorage.id = '$id';sessionStorage.name = '$name';open('html/mine.html','_self')</script>");
				return false;
			}
		}
		echo("<script>sessionStorage.err = 'error';open('html/login.html','_self');</script>");
	}
	mysqli_close($conn);
?>